//
//  QSProblemReportSecondCell.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/25.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSProblemReportSecondCell.h"
#import "BRPickerView.h"
#import "QSSelectCompanyViewController.h"
#import "QSOtherSelectCompanyViewController.h"
@implementation QSProblemReportSecondCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self configSubView];
}

- (void)configSubView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.layer.cornerRadius = 8;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.backgroundColor = [UIColor QSColorWhiteFFFFFF];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.mas_leading).offset(kRealValue(10));
        make.trailing.equalTo(self.mas_trailing).offset(kRealValue(-10));
        make.top.equalTo(self.mas_top).offset(kRealValue(2));
        make.bottom.equalTo(self.mas_bottom).offset(kRealValue(0));
    }];
    
    
    _selectEnterpriseLabel.layer.cornerRadius = 5;
    _selectEnterpriseLabel.layer.borderColor = [UIColor QSColorGrayEAEAEA].CGColor;
    _selectEnterpriseLabel.layer.borderWidth = 0.5;
    _selectEnterpriseLabel.userInteractionEnabled = YES;
    UITapGestureRecognizer *selectCompanyTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectCompanyAction:)];
    [_enterpriseLabel setAttributedText:[UILabel setLabelTextColorWithString:_enterpriseLabel.text Range:NSMakeRange(4, 1) andColor:[UIColor redColor]]];
    [_selectEnterpriseLabel addGestureRecognizer:selectCompanyTap];
    

}

- (void)selectTownAction:(UITapGestureRecognizer *)sender{
   
    if (_townArr.count) {
        NSMutableArray *copyCompanyArr = [NSMutableArray array];
        for (NSDictionary *dic in _townArr) {
            NSString *companyName = [dic objectForKey:@"name"];
            [copyCompanyArr addObject:companyName];
        }
        [BRStringPickerView showStringPickerWithTitle:@"请选择街道" dataSource:copyCompanyArr defaultSelValue:nil resultBlock:^(id selectValue) {
            for (NSDictionary *dic in self.townArr) {
                if ([dic[@"name"] isEqualToString:selectValue]) {
                    self.selectStreetLabel.text = selectValue;
                    //取出选中街道id赋值
                    if (self.didSelectTownFinishBlock) {
                        self.didSelectTownFinishBlock(dic[@"id"]);
                    }
                    break;
                }
            }
        }];
    }else{
        [QSAppKeyWindow showAutoHideHudWithText:@"没有街道可以选择!"];
    }
}

- (void)selectCompanyAction:(UITapGestureRecognizer *)sender{
//    QSSelectCompanyViewController *vc = [QSSelectCompanyViewController new];
//    vc.didSelectCompanyFinish = ^(NSString *companyKey, NSString *companyName) {
//        self.selectEnterpriseLabel.text = companyName;
//        NSLog(@"%@", companyKey);
//        if (self.didSelectCompanyFinishBlock) {
//            self.didSelectCompanyFinishBlock(companyKey);
//        }
//    };
    QSOtherSelectCompanyViewController *vc = [QSOtherSelectCompanyViewController new];
    vc.didSelectCompanyBlock = ^(QSVisitInfoCompanyListModel *model) {
        self.selectEnterpriseLabel.text = model.companyName;
        NSLog(@"%@",model.companyKey);
        if (self.didSelectCompanyFinishBlock) {
            self.didSelectCompanyFinishBlock(model.companyKey);
        }
    };
    
    [[UIViewController currentViewController].navigationController pushViewController:vc animated:YES];
//     if (self.companyArr.count) {
//            NSMutableArray *copyCompanyArr = [NSMutableArray array];
//            for (NSDictionary *dic in self.companyArr) {
//                NSString *companyName = dic[@"label"];
//                [copyCompanyArr addObject:companyName];
//            }
//            [BRStringPickerView showStringPickerWithTitle:@"请选择公司" dataSource:copyCompanyArr defaultSelValue:nil resultBlock:^(id selectValue) {
//                for (NSDictionary *dic in self.companyArr) {
//                    if ([dic[@"label"] isEqualToString:selectValue]) {
//                        self.selectEnterpriseLabel.text = selectValue;
//                        //取出选中公司key赋值
//                        if (self.didSelectCompanyFinishBlock) {
//                            self.didSelectCompanyFinishBlock(dic[@"key"]);
//                        }
//                        break;
//                    }
//                }
//            }];
//        }else{
//            [QSAppKeyWindow showAutoHideHudWithText:@"请先绑定公司!"];
//        }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
